package com.aircjm.thread;

import org.junit.Test;

/**
 * Created by chenjiaming on 2016/8/25.
 */
public class ThreadController {
    public static int addDigits(int num) {
        while (num >= 10) {
            String s = String.valueOf(num);
            String[] split = s.split("");
            if (split.length > 1) {
                int stringNum = 0;
                for (int i = 0; i < split.length; i++) {
                    if (split[i].isEmpty()){
                        continue;
                    }
                    stringNum = stringNum + Integer.valueOf(split[i]);
                }
                num = stringNum;
            }
        }
        return num;
    }

    public static void main(String[] args) {
        System.out.println(addDigits(111));
    }


    /**
     * 起一个线程单独跑线程内的代码，业务流程从启动线程后继续执行
     */
    @Test
    public void testThread() throws InterruptedException {
        Threader threader = new Threader();
        Thread thread1 = new Thread(threader);

        thread1.start();
        // join 方法等待当前线程结束才会往下执行
        thread1.join();
        System.out.println("多线程");
    }


    @Test
    public void testThreadYeild(){
        Thread t1 = new Thread(new Threader());

    }

}


class Threader implements Runnable{

    public static int i = 1;

    public void run() {
        while (true){
            i++;
            System.out.println(i);
        }
        // System.out.println(i);
    }
}